{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/member_list.css" />
<script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script>

{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="20%" style="text-align: left;">
			<button class="btn-common btn-small" onclick="open_Add_Trade()" style="margin:0 5px 0 0 !important;">添加订单</button>
		</th>

		<th>
			<select id="tid_sort"  class="select-common middle">
				<option value ="1">今日最早</option>
				<option value ="-1">默认排序</option>
			</select>
			<select id="coin_count_ser"  class="select-common middle">
				<option value ="-1">数量</option>
				<option value ="1">1</option>
				<option value ="5">5</option>
				<option value ="10">10</option>
				<option value ="30">30</option>
				<option value ="50">50</option>
				<option value ="100">100</option>
			</select>
			<select id="trade_status"  class="select-common middle">
				<option value ="">全部</option>
				<option value ="0">挂买单</option>
				<option value ="1">待付款</option>
				<option value ="2">待收款</option>
				<option value ="3">已完成</option>
				<option value ="-1">已终止</option>
			</select>
			<input type="text" id ='post_user_tel' placeholder="输入买方完整手机号" class="input-common middle" />
			<input type="text" id ='op_user_tel' placeholder="输入卖方完整手机号" class="input-common middle" />
			<input type="button" onclick="searchData()" value="搜索" class="btn-common" />

		</th>
	</tr>
</table>
<table class="table-class" >
	<thead>
		<tr align="center">
			<th>ID</th>
			<th class="tal">买方</th>
			<th class="tal">卖方</th>
			<th class="tal">状态</th>
			<th>数量</th>
			<th>价格</th>
			<th>总价</th>
			<th>流水号</th>
			<th align="left">时间</th>
			<th>支付凭证</th>
			<th style="width: 150px">优先匹配</th>
			<th style="width: 100px">操作</th>
		</tr>
	</thead>
	<tbody id="my-table"></tbody>
</table>


<!-- 后台添加订单 -->
<div class="modal fade hide" id="add_trade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">添加订单</h4>
			</div>
			<div class="modal-body">
				<div class="modal-infp-style">
					<table class="modal-tab">
						<tr>
							<td style="width:20%">姓名</td>
							<td colspan='3'><input type="text" id="real_name" class="input-common" value="0"/></td>
						</tr>
						<tr>
							<td style="width:20%">矿机</td>
							<td colspan='3'>
								合约云矿机
							</td>
						</tr>
						<tr>
							<td style="width:20%">数量</td>
							<td colspan='3'>
								<select id="coin_count" name="coin_count" class="select_pig">
									<option value="0">请选择买入合约数量</option>
									{foreach name="$count_list" item="vo"}
									<option value="{$vo}">{$vo}</option>
									{/foreach}
								</select>
							</td>
						</tr>
						<tr>
							<td style="width:20%">手机号码</td>
							<td colspan='3'><input type="text" id="user_tel" value="15295105177" class="input-common"/></td>
						</tr>

						<tr>
							<td style="width:20%">显示手机号码</td>
							<td colspan='3'><input type="text" id="dis_user_tel" class="input-common"  value="0"/></td>
						</tr>
						<tr>
							<td style="width:20%">时间戳</td>
							<td colspan='3'><input type="text" id="time" class="input-common" value=""/></td>
						</tr>
					</table>

					备注：显示手机号码和姓名如果输入0，则会自动生成。
				</div>
			</div>

			<div class="modal-footer">
				<input type="hidden" id="lock_userid" />
				<button class="btn btn-primary" onclick="act_add_trade()">保存</button>
				<button class="btn" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>

</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function LoadingInfo(page_index) {
        var post_user_tel = $("#post_user_tel").val();
        var op_user_tel = $("#op_user_tel").val();
        var trade_status = $("#trade_status").val();
        var coin_count_ser = $("#coin_count_ser").val();
		var tid_sort = $("#tid_sort").val();

        $.ajax({
            type : "post",
            url : document.location,
            data : {
                "page_index" : page_index,
                "page_size" : $("#showNumber").val(),
				"trade_status" :trade_status,
				"post_user_tel" :post_user_tel,
				"op_user_tel":op_user_tel,
				"coin_count_ser":coin_count_ser,
				"tid_sort":tid_sort
            },
            success : function(data) {
                if (data["data"].length > 0) {
                    $("#my-table").empty();
                    for (var i = 0; i < data["data"].length; i++) {
                        var html = '';
                        html += '<tr align="center">';
                        html += '<td class="tal">'+ data["data"][i]["post_uid"] +'</td>'
                        html += '<td class="tal" onclick=view_Member('+ data["data"][i]["post_uid"] +')>'+ data["data"][i]["real_name"] +'<br>'+ data["data"][i]["user_tel"] +'<br>ZSC：'+ data["data"][i]["post_point"] +'<br>买币数量：'+ data["data"][i]["post_donation"] +'<br>注册时间：'+ timeStampTurnTime(data["data"][i]["reg_time"]) +'</td>'
                        html += '<td class="tal" onclick=view_Member('+ data["data"][i]["op_uid"] +')>'+ data["data"][i]["op_real_name"] +'<br>'+ data["data"][i]["op_user_tel"] +'</td>'
                        html += '<td class="tal">';
                        if(data["data"][i]["trade_status"]===0)
                        {
                            html += '挂单';
                        }
                        else if(data["data"][i]["trade_status"]===1)
                        {
                            html += '<font color="red">待付款</font>';
                        }
                        else if(data["data"][i]["trade_status"]===2)
                        {
                            html += '<font color="red">待收款</font>';
                        }
                        else if(data["data"][i]["trade_status"]===3)
                        {
                            html += '<font color="green">已完成</font>';
                        }
                        else if(data["data"][i]["trade_status"]===-1)
                        {
                            html += '<font color="red">已终止</font>';
                        }
                        else
                        {
                            html += '<font color="red">已取消</font>';
                        }
                        html += '</td>';

                        html += '<td class="tal">'+data["data"][i]["coin_count"]+'</td>';
                        html += '<td class="tal">'+data["data"][i]["coin_price"]+'</td>';
                        html += '<td class="tal">'+data["data"][i]["total_price"]+'</td>';
                        html += '<td class="tal">'+data["data"][i]["trade_no"]+'</td>';
                        html += '<td class="tal"  align="left">挂单：'+timeStampTurnTime(data["data"][i]["add_time"])+'<br>匹配：'+timeStampTurnTime(data["data"][i]["trade_time"])+'<br>支付：'+timeStampTurnTime(data["data"][i]["pay_time"])+'<br>收款：'+timeStampTurnTime(data["data"][i]["finish_time"])+'</td>';

						if(data["data"][i]["pay_pic"]) {
                            html += '<td class="tal"><a href="'+data["data"][i]["pay_pic"]+'" target=_blank><img src="'+data["data"][i]["pay_pic"]+'" style="height: 100px"></a></td>';
                        }
                        else{
                            html += '<td class="tal">尚未上传</td>';
						}


                        /*
						if(data["data"][i]["trade_status"] == 0 && data["data"][i]["trade_type"] == 0) {
							html += '<td class="tal"><a onclick="up_record(' + data["data"][i]["tid"] + ')">优先匹配</a> | <a onclick="sell(' + data["data"][i]["tid"] + ')">立即匹配</a></td>';
						}
						else {
							html += '<td class="tal">' + data["data"][i]["trade_type"] + '</td>';
						}

                         */
						html += '<td class="tal">' + data["data"][i]["trade_type"] + '</td>';

                        if(data["data"][i]["trade_status"] == 2) {
                            html += '<td class="tal"><a onclick="delete_record(' + data["data"][i]["tid"] + ',1)">传假图</a></td>';
                        }
                        else{
                                html += '<td class="tal"><a onclick="delete_record(' + data["data"][i]["tid"] + ',0)">删除</a></td>';
                            }
                        html += '</tr>';
                        $("#my-table").append(html);
                    }
                } else {
                    var html = '<tr align="center"><td colspan="12">暂无符合条件的数据记录</td></tr>';
                    $("#my-table").html(html);
                }
                initPageData(data["page_count"],data['data'].length,data['total_count']);
                $("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
            }
        });
    }
    //搜索
    function searchData(){
        LoadingInfo(1);
    }
    // 删除记录
    function delete_record(tid,i){
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $.ajax({
                        type : "post",
                        url : "{:__URL('ADMIN_MAIN/Mine/deleteCoinTrade')}",
                        data : {
                            "tid" : tid,
							"i" : i
						},
                        dataType : "json",
                        success : function(data) {

                            showTip(data["message"],'success');

							LoadingInfo(getCurrentIndex(tid,'#productTbody'));
                        }
                    });
					$(this).dialog('close');

                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                },
            },
            contentText:"确定要处理这条记录吗？",
        });
    }

	//后台添加挂单
	function open_Add_Trade() {
		$("#add_trade").modal("show");
	}


	//后台添加挂单提交
	function act_add_trade() {
		var real_name = $("#real_name").val();
		var coin_count = $("#coin_count").val();
		var user_tel = $("#user_tel").val();
		var dis_user_tel = $("#dis_user_tel").val();
		var time = $("#time").val();
		//alert(uid);
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/Mine/actAddTrade')}",
			data : { "real_name" : real_name, "coin_count" : coin_count,"user_tel":user_tel,"time":time,"dis_user_tel":dis_user_tel,"level_id":6},
			success : function(data) {
				if (data["code"] > 0) {
					showTip(data['message'],'success');
				}else{
					showTip(data['message'],'error');
				}
			}
		});
	}

	// 立即匹配
	function sell(tid) {
		$( "#dialog" ).dialog({
			buttons: {
				"确定": function() {
					$.ajax({
						type : "post",
						url : "{:__URL('ADMIN_MAIN/Mine/sellCoinTrade')}",
						data : {
							"tid" : tid
						},
						dataType : "json",
						success : function(data) {
							LoadingInfo(getCurrentIndex(tid,'#productTbody'));
							showTip(data["message"],'success');
						}
					});
					$(this).dialog('close');
					//window.location.reload();
				},
				"取消,#e57373": function() {
					$(this).dialog('close');
				},
			},
			contentText:"确定要立即匹配这条记录吗？",
		});
	}



	// 优先匹配订单
	function up_record(tid){
		$( "#dialog" ).dialog({
			buttons: {
				"确定": function() {
					$.ajax({
						type : "post",
						url : "{:__URL('ADMIN_MAIN/Mine/upCoinTrade')}",
						data : {
							"tid" : tid
						},
						dataType : "json",
						success : function(data) {
							LoadingInfo(getCurrentIndex(tid,'#productTbody'));
							showTip(data["message"],'success');
						}
					});
					$(this).dialog('close');
				},
				"取消,#e57373": function() {
					$(this).dialog('close');
				},
			},
			contentText:"确定要优先匹配这条记录吗？",
		});
	}

	$(document).ready(function(){

		// 开始写 jQuery 代码...
		var timestamp = Date.parse(new Date())/1000;
		$("#time").val(timestamp);
	});
</script>
{/block}